package ysq.xyg.sys.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.service.impl.BaseServiceImpl;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.sys.dao.SysLogUseDao;
import ysq.xyg.sys.model.po.SysLogUse;
import ysq.xyg.sys.model.po.SysUser;
import ysq.xyg.sys.model.vo.SysLogUseVo;
import ysq.xyg.sys.service.SysLogUseService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * 系统管理-操作日志service实现
 *
 * @author shengQiang yu
 * @date 2019-3-28 16:41:31
 */
@Service("sysLogUseService")
public class SysLogUseServiceImpl extends BaseServiceImpl<SysLogUse> implements SysLogUseService {

    @Resource
    private SysLogUseDao sysLogUseDao;

    private SysLogUse sysLogUse;

    @Autowired
    public void setBaseDao(SysLogUseDao sysLogUseDao) {
        this.baseDao = sysLogUseDao;
    }


    /**
     * 分页查询
     *
     * @param sysLogUseVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @return ReturnEntity 对象
     * @author shengQiang yu
     * @date 2019-3-28 16:41:31
     */
    public ReturnEntity page(SysLogUseVo sysLogUseVo, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" create_time desc");
        List<SysLogUse> list = acceptList(sysLogUseVo);
        PageInfo<SysLogUse> page=new PageInfo<SysLogUse>(list);
        return new ReturnEntity(page.getList(),page.getTotal(),page.isHasNextPage());
    }



    /**
     * 获取集合
     *
     * @param sysLogUseVo 对象
     * @return List<BaseDict> BaseDict集合
     * @author shengQiang yu
     * @date 2019-3-28 16:41:31
     */
    public List<SysLogUse> acceptList(SysLogUseVo sysLogUseVo){
        Example example = new Example(SysLogUse.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(sysLogUseVo.getModuleName())){
            criteria.andLike("moduleName","%" + sysLogUseVo.getModuleName()+"%");
        }
        if(StringUtil.isNotEmpty(sysLogUseVo.getClassName())){
            criteria.andLike("ClassName","%" + sysLogUseVo.getClassName()+"%");
        }
        if(StringUtil.isNotEmpty(sysLogUseVo.getMethod())){
            criteria.andLike("method","%" + sysLogUseVo.getMethod()+"%");
        }
        if(StringUtil.isNotEmpty(sysLogUseVo.getBusinessType())){
            criteria.andEqualTo("businessType",sysLogUseVo.getBusinessType());
        }
        example.setOrderByClause(" create_time desc");
        return sysLogUseDao.selectByExample(example);
    }
}
